<template>
	<view class="full box relative bg-primary flex-col warranty-page">
		<mescroll-uni @init="mescrollInit" :fixed="false" @down="downCallback" @up="upCallback">
			<view class="header-wrap"></view>
			<view class="content-box">
				<view class="q-item" v-for="(item,index) in list" :key="index">
					<view class="item-header" @click="handleOpenItem(item)">
						<view class="q-title">
							<text>{{ item.title }}</text>
						</view>
						<image src="/static/img/chevron-left.png" class="chevron-img"
							:class="[item.open ? 'active' : '']" mode="aspectFill"></image>
					</view>
					<view class="q-contenr" v-if="item.open">
						<text>{{ item.content }}</text>
					</view>
				</view>
			</view>
		</mescroll-uni>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import { request, showLoading, toast } from "@/utils/tool.js"
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				list: []
			}
		},
		methods: {
			upCallback(ev) {
				const { num, size } = ev
				this.initData(num, size)
			},
			async initData(page, limit) {
				const hide = showLoading("正在获取")
				const resp = await request({
					url: "/baoxiu/lists",
					method: "GET",
					data: { page_no: page, page_size: limit }
				}).catch(hide)
				const { lists, count } = resp.data
				if (page === 1) this.list = []
				this.list.push(...lists.map(item => {
					item.open = false
					return item
				}))
				this.mescroll.endBySize(lists.length, count)
				hide()
			},
			handleOpenItem(rowItem) {
				rowItem.open = !rowItem.open
			}
		},
	}
</script>

<style lang="scss" scoped>
	.warranty-page {
		padding: 24rpx 30rpx 0;
		box-sizing: border-box;
		position: relative;

		.content-box {
			margin-top: 24rpx;
			padding: 48rpx 24rpx;
			box-sizing: border-box;
			position: relative;
			background-color: #fff;
			box-shadow: 0rpx 8rpx 8rpx 0rpx rgba(0, 0, 0, 0.05);
			border-radius: 14rpx 14rpx 14rpx 14rpx;

			.q-item {
				margin-bottom: 20rpx;

				&:last-child {
					margin-bottom: 0;
				}

				.q-contenr {
					padding: 14rpx 16rpx 0;
					font-weight: 400;
					font-size: 24rpx;
					color: #565656;
					line-height: 36rpx;
					word-break: break-all;
					white-space: pre-wrap;
				}

				.item-header {
					display: flex;
					align-items: flex-start;

					.chevron-img {
						width: 40rpx;
						height: 40rpx;
						margin-left: auto;

						&.active {
							transform: rotate(90deg);
						}
					}



					.q-title {
						font-weight: 400;
						font-size: 32rpx;
						color: #4A4A4A;
						line-height: 36rpx;
						word-break: break-all;
						white-space: pre-wrap;
						width: 580rpx;
					}
				}
			}
		}

		.header-wrap {
			width: 100%;
			height: 180rpx;
			border-radius: 12rpx 12rpx 12rpx 12rpx;
			background-color: #fff;
		}
	}
</style>